<?php
/**
 * Name: AdminAuthController.class.php
 * Description:
 * User: DIY
 * Date: 2016/9/6
 * Time: 18:36
 */

namespace Admin\Controller;


use Admin\Library\BootstrapPage;
use Common\Logic\AdminAuthLogic;
use Common\Model\AdminAuthModel;


class AdminAuthController extends BaseController{

    /*
     * 列表页面
     * */
    public function index(){
        $data = array(
            '1'=>'1',
        );
        if(I('get.title')){
            $data['title'] = array('like','%'.I('get.title').'%');
        }
        if(I('get.url')){
            $data['url'] = array('like','%'.I('get.url').'%');
        }
        if(I('get.hide')!=''){
            $data['hide'] = I('get.hide');
        }
        $AdminAuthModel = new AdminAuthModel();
        $count = $AdminAuthModel->where($data)->count();
        $Page = new BootstrapPage($count,20);
        $list['list'] = $AdminAuthModel->where($data)->limit($Page->firstRow.','.$Page->listRows)->select();
        $list['page'] = $Page->show();// 分页显示输出
        $this->assign('list',$list);
        $this->display();
    }

    /*
     * 新增权限
     * */
    public function add(){
        if(IS_POST){
            $AdminAuthModel = new AdminAuthModel();
            if($AdminAuthModel->create()){
                $result = $AdminAuthModel->add(); // 写入数据到数据库
                if($result){
                    $this->success('保存成功',U('Admin/AdminAuth/index'));
                }
            }
            $this->error('保存失败');
        }
        else{
            $AdminAuthLogic = new AdminAuthLogic();
            $menu = $AdminAuthLogic->getAdminAuthList();
            $this->assign('menu',$menu);
            $this->display();
        }
    }

    /*
     * 删除
     * */
    public function del($id){
        $AdminAuthModel = new AdminAuthModel();
        $AdminAuthModel->delete($id);
        $this->success('删除成功',U('Admin/AdminAuth/index'));

    }

    /*
     * 编辑
     * */
    public function edit($id){
        $AdminAuthModel = new AdminAuthModel();
        if(IS_POST){
            if($AdminAuthModel->create()){
                $result = $AdminAuthModel->save();
                if($result){
                    $this->success('更新成功',U('Admin/AdminAuth/index'));
                }
            }
            $this->error('更新失败');

        }
        else{
            $AdminAuthLogic = new AdminAuthLogic();
            $menu = $AdminAuthLogic->getAdminAuthList();
            $auth = $AdminAuthModel->find($id);
            $this->assign('auth',$auth);
            $this->assign('menu',$menu);
            $this->display();
        }
    }
}